package com.LA_houseLease.admin.controller.user;



import com.LA_houseLease.admin.service.UserInfoService;
import com.LA_houseLease.admin.vo.user.UserInfoQueryVo;
import com.LA_houseLease.common.result.Result;
import com.LA_houseLease.pojo.entity.UserInfo;
import com.LA_houseLease.pojo.enums.BaseStatus;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@CrossOrigin(origins = "*")
@Slf4j
@Tag(name = "用户信息管理")
@RestController
@RequestMapping("/admin/user")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @Operation(summary = "分页查询用户信息")
    @GetMapping("page")
    public Result<IPage<UserInfo>> pageUserInfo(@RequestParam long current, @RequestParam long size, UserInfoQueryVo queryVo) {
        log.warn("分页查询用户信息--UserInfoController.pageUserInfo");
        //todo 分页查询用户信息中对于phone为进行!=''判断
        Page<UserInfo> page = new Page<>(current, size);
        IPage<UserInfo> userInfoPage=userInfoService.pageUserInfo(page,queryVo);
        return Result.ok(userInfoPage);
    }

    @Operation(summary = "根据用户id更新账号状态")
    @PostMapping("updateStatusById")
    public Result updateStatusById(@RequestParam Long id, @RequestParam BaseStatus status) {
        log.warn("根据用户id更新账号状态--UserInfoController.updateStatusById");
        LambdaUpdateWrapper<UserInfo> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(UserInfo::getId,id);
        lambdaUpdateWrapper.set(UserInfo::getStatus,status);
        userInfoService.update(lambdaUpdateWrapper);
        return Result.ok();
    }
}
